package org.liuchang.incomeAndExpenses;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import org.liuchang.ext.DatePicker;
import org.liuchang.util.DBUtil;
import org.liuchang.util.Item;

public class OperateDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField textField;
	private JTextField textField_1;
	private JComboBox<Item> comboBox;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			OperateDialog dialog = new OperateDialog();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public OperateDialog() {
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		JLabel lblNewLabel = new JLabel("日期");
		lblNewLabel.setFont(new Font("Dialog", Font.PLAIN, 15));
		lblNewLabel.setBounds(59, 42, 72, 28);
		contentPanel.add(lblNewLabel);
		DatePicker dp = new DatePicker();
		dp.getEditor().setFont(new Font("Dialog", Font.PLAIN, 15));
		dp.setFont(new Font("Dialog", Font.PLAIN, 15));
		dp.setBounds(143, 42, 228, 28);
		contentPanel.add(dp);
		JLabel lblNewLabel_1 = new JLabel("类型");
		lblNewLabel_1.setFont(new Font("Dialog", Font.PLAIN, 15));
		lblNewLabel_1.setBounds(59, 82, 88, 28);
		contentPanel.add(lblNewLabel_1);
		JLabel lblNewLabel_2 = new JLabel("名称");
		lblNewLabel_2.setFont(new Font("Dialog", Font.PLAIN, 15));
		lblNewLabel_2.setBounds(59, 125, 88, 28);
		contentPanel.add(lblNewLabel_2);
		JLabel lblNewLabel_3 = new JLabel("金额");
		lblNewLabel_3.setFont(new Font("Dialog", Font.PLAIN, 15));
		lblNewLabel_3.setBounds(59, 166, 88, 28);
		contentPanel.add(lblNewLabel_3);
		
		
		Vector<Item> model = new Vector<Item>();
		DBUtil dbUtil = new DBUtil();
		ResultSet rs = dbUtil.executeQuery("SELECT ID,NAME FROM TBL_TYPE");
		try {
			while (rs.next()) {
				Item item = new Item(rs.getInt(1),rs.getString(2));
		        model.addElement(item);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		comboBox = new JComboBox<Item>(model);
		comboBox.setFont(new Font("Dialog", Font.PLAIN, 15));
		comboBox.setBounds(143, 79, 228, 34);
		contentPanel.add(comboBox);
		
		textField = new JTextField();
		textField.setFont(new Font("Dialog", Font.PLAIN, 15));
		textField.setBounds(143, 126, 228, 28);
		contentPanel.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("Dialog", Font.PLAIN, 15));
		textField_1.setBounds(143, 167, 228, 28);
		contentPanel.add(textField_1);
		textField_1.setColumns(10);
		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
		getContentPane().add(buttonPane, BorderLayout.SOUTH);
		JButton okButton = new JButton("OK");
		okButton.setActionCommand("OK");
		buttonPane.add(okButton);
		getRootPane().setDefaultButton(okButton);
		JButton cancelButton = new JButton("Cancel");
		cancelButton.setActionCommand("Cancel");
		buttonPane.add(cancelButton);
	}
}
